package com.ywd.platform.websocket.util;

import org.springframework.web.socket.WebSocketSession;

import java.util.Map;

public class SessionUserUtil {

    private static final String SESSION_USER = "SESSION_USER";

    /**
     * 设置用户
     *
     * @param userId       用户
     * @param attributes attributes
     */
    public static void setUser(Long userId, Map<String, Object> attributes) {
        attributes.put(SESSION_USER, userId);
    }

    /**
     * 获取用户
     */
    public static Long getUserId(WebSocketSession session) {
        return (Long) session.getAttributes().get(SESSION_USER);
    }

}
